package diamondexercises;

/**
 * Created by ravindra on 18/7/14.
 */

class DriveDiamondWithName{
    public static void main(String[] Args){
        int size;
        String input = null;
        String myName = "Ravindra";
        DiamondWithName diamondWithName = new DiamondWithName();

        System.out.println("To exit type -> quit. \n");

        input = Utilities.readInputFromConsole("size");


        while(!input.equals("quit")){
            size = Integer.parseInt(input);
            diamondWithName.print(size, myName);

            input = Utilities.readInputFromConsole("size");
        }
    }
}

class DiamondWithName {

    void print(int size, String myName) {
        int noOfSpaces = size - 1;

        if (size < 2) {
            System.out.println("that is not a diamond!!");
            return;
        }
        upperHalfOfDiamond(size, noOfSpaces);

        System.out.println(myName);

        noOfSpaces = 1;

        lowerHalfOfDiamond(size, noOfSpaces);

    }

    private void lowerHalfOfDiamond(int size, int noOfSpaces) {
        for (int i = size - 2; i >= 0; i--) {

            printSpaces(noOfSpaces);
            noOfSpaces++;
            int noOfAsterisk = (2 * i) + 1;

            for (int j = 0; j < noOfAsterisk; j++) {
                System.out.print("*");
            }

            System.out.println("");
        }
    }

    private void upperHalfOfDiamond(int size, int noOfSpaces) {
        for(int i = 0; i < size - 1; i++){
            printSpaces(noOfSpaces);
            noOfSpaces--;
            int noOfAsterisk = (2 * i) + 1;

            for(int j = 0; j < noOfAsterisk ; j++){
                System.out.print("*");
            }

            System.out.println("");
        }
    }


    private void printSpaces(int noOfSpaces){
        for(int i = 0; i < noOfSpaces; i++){
            System.out.print(" ");
        }
    }
}
